﻿using System;using ERP_RORZE_SYSTEM;
using System.Collections.Generic;
using System.Data;using ERP_RORZE_SYSTEM;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_DLL.Product.database;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Product
{
    public class ClsBusOderDAO: ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();
        
        public DataTable GetAll()
        {
            string sql = clsConstantsFuction.ClsFuctionBusOder.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllMONoUpdate()
        {
            string sql = clsConstantsFuction.ClsFuctionBusOder.GetAllMONoUpdate;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetPartID()
        {
            string sql = clsConstantsFuction.ClsFuctionPart.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        public DataTable GetMONo()
        {
            string sql = clsConstantsFuction.ClsFuctionMO.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        public void Insert(ClsBusOderTable b)
        {

            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsBusOderSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BOderNo, SqlDbType.NVarChar, b.BOderNo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.planNo, SqlDbType.NVarChar, b.PlanNo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.PartID, SqlDbType.NVarChar, b.PartID),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Qty, SqlDbType.Int, b.Qty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Dealine, SqlDbType.DateTime, b.Dealine),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.RawQty, SqlDbType.Int,b.RawQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.HelisertQty, SqlDbType.Int, b.HelisertQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BlastQty, SqlDbType.Int, b.BlastQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.MOQty, SqlDbType.Int, b.MOQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Started, SqlDbType.Bit, b.Started),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Finished, SqlDbType.Bit, b.Finished),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Change, SqlDbType.NVarChar, b.Change),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.ChangeDate, SqlDbType.DateTime, b.ChangeDate),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Imported, SqlDbType.Bit, b.Imported),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Note, SqlDbType.NVarChar, b.Note),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.ImportFrom, SqlDbType.NVarChar, b.ImportFrom)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionBusOder.Insert,parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show(""+e);
            }
            
        }
        public void Delete(ClsBusOderTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BOderNo, SqlDbType.NVarChar, b.BOderNo)
                    
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionBusOder.Delete, parameter, true);

        }
        public void Update(ClsBusOderTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsBusOderSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BOderNo, SqlDbType.NVarChar, b.BOderNo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.planNo, SqlDbType.NVarChar, b.PlanNo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.PartID, SqlDbType.NVarChar, b.PartID),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Qty, SqlDbType.Int, b.Qty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Dealine, SqlDbType.DateTime, b.Dealine),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.RawQty, SqlDbType.Int,b.RawQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.HelisertQty, SqlDbType.Int, b.HelisertQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BlastQty, SqlDbType.Int, b.BlastQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.MOQty, SqlDbType.Int, b.MOQty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Started, SqlDbType.Bit, b.Started),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Finished, SqlDbType.Bit, b.Finished),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Change, SqlDbType.NVarChar, b.Change),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.ChangeDate, SqlDbType.DateTime, b.ChangeDate),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Imported, SqlDbType.Bit, b.Imported),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Note, SqlDbType.NVarChar, b.Note),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.ImportFrom, SqlDbType.NVarChar, b.ImportFrom)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void CancelBusOder(ClsBusOderTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BOderNo, SqlDbType.NVarChar, b.BOderNo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Started, SqlDbType.Bit, b.Started),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Finished, SqlDbType.Bit, b.Finished),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Change, SqlDbType.NVarChar, b.Change),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.ChangeDate, SqlDbType.DateTime, b.ChangeDate)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.CancelBusOder, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void CancelMO(ClsMOTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMOSP.Started, SqlDbType.Bit, b.Started),
                    CreateParameter(clsConstantsSP.ClsMOSP.Finished, SqlDbType.Bit, b.Finished),
                    CreateParameter(clsConstantsSP.ClsMOSP.Note, SqlDbType.NVarChar, b.Note)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.CancelMO, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void CancelMOOption(ClsMOOptionTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMOSP.Finished, SqlDbType.Bit, b.Finished),
                    CreateParameter(clsConstantsSP.ClsMOSP.Note, SqlDbType.NVarChar, b.Note)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.CancelMOOption, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeadlineBusOder(ClsBusOderTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BOderNo, SqlDbType.NVarChar, b.BOderNo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Dealine, SqlDbType.DateTime, b.Dealine),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Change, SqlDbType.NVarChar, b.Change),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.ChangeDate, SqlDbType.DateTime, b.ChangeDate)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.DeadlineBusOder, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeadlineMO(ClsMOTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMOSP.DeadLine, SqlDbType.DateTime, b.DeadLine),
                    CreateParameter(clsConstantsSP.ClsMOSP.Note, SqlDbType.NVarChar, b.Note)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.DeadlineMO, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DealineMOOption(ClsMOOptionTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMOSP.DeadLine, SqlDbType.DateTime, b.Deadline)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.DeadlineMOOption, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void QtyChangeBusOder(ClsBusOderTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsBusOderSP.BOderNo, SqlDbType.NVarChar, b.BOderNo),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Qty, SqlDbType.Int, b.Qty),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.Change, SqlDbType.NVarChar, b.Change),
                    CreateParameter(clsConstantsSP.ClsBusOderSP.ChangeDate, SqlDbType.DateTime, b.ChangeDate)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionBusOder.DeadlineBusOder, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
    }
}
